﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DBModel
{
    public partial class OtherQualification
    {
        public override string ToString()
        {
            return string.Format("{0}, {1}, {2} -> {3} ", QualificationId, Title,
                StartDate.ToShortDateString(), EndDate.ToShortDateString());
        }
        public string ToHtml()
        {
            return string.Format("{0} &ndash; {1}<br /> {2}<br /> {3}<br />{4}<br />",
                StartDate.ToShortDateString(), EndDate.ToShortDateString(),
                Title, Organizer, QualificationDescription);
        }

    }
    public static class OtherQualificationDB
    {
        public static OtherQualification GetOtherQualificationById(int id)
        {
            return DB.Context.OtherQualifications
                .Where(q => q.QualificationId == id)
                .SingleOrDefault(s => !s.IsDeleted);
        }

        public static bool DeleteOterQualificationById(int id)
        {
            OtherQualification otherQualificationToDelete = GetOtherQualificationById(id);
            if (otherQualificationToDelete != null)
            {
                otherQualificationToDelete.IsDeleted = true;
                int affectedRows = DB.Context.SaveChanges();
                return (affectedRows > 0);
            }
            return false;
        }
    }
}
